#include <bits/stdc++.h>
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
void write(int x)
{
    if(x<0)
    {
        x=-x;
        putchar('-');
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
int T,n,ans;
int a[200005];
bool vis[16][230][2][16][16];
void dfs(int x,int c,int s,int r,int y)
{
    if(x>n)
    {
        ans=max(ans,s);
        return;
    }
    if(vis[x][c][s][r][y])
        return;
    vis[x][c][s][r][y]=1;
    int t=0;/*
    if(x==4)
       {
    write(x);putchar(' ');write(c);putchar(' ');write(s);putchar(' ');write(r);putchar(' ');write(y);putchar(' ');write(ans);puts("");

       }*/
    if(c==0)
    {
        if(a[x]==a[r] && x!=r)
            t+=a[x];
        r=x;
    }
    if(c==1)
    {
        if(a[x]==a[y] && x!=y)
            t+=a[x];
        y=x;
    }
    dfs(x+1,0,s+t,r,y);
    dfs(x+1,1,s+t,r,y);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--)
    {
        memset(vis,0,sizeof(vis));
        n=read();
        ans=0;
        for(int i=1;i<=n;i++)
            a[i]=read();
        dfs(1,0,0,1,0);
        //cout<<endl;
        dfs(1,1,0,0,1);
        write(ans);
        puts("");
    }
    return 0;
}
